// *** LICENSE HEADER ***
// Filename: ./resource.h
// This file is part of Nodewarz 0.1
// Nodewarz is a 3d OpenGL strategy game
// Copyright (C) 2007 CZestmyr
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
// *** END LICENSE HEADER ***
#ifndef _NODEWARS_RESOURCE_H
#define _NODEWARS_RESOURCE_H

#include <SDL.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "game.h"
#include "fonts.h"
#include "node.h"
#include "resourcelist.h"
#include "light.h"
#include "lightmanager.h"
#include "particlesystem.h"
#include "imagefunctions.h"
#include "definitions.h"

//Definitions of the resource types
#define RT_ATTACK 0
#define RT_DEFENCE 1
#define RT_LIVES 2
#define RT_CREDITS 3
#define RT_TAKEOVER 4

class resource;
class game;
class light;
class fonts;

//Abstract class that represents a game energy or money resource
class resource{
    public:
        resource (float posX, float posY, float radius, int ammount, game* newGame);
        ~resource();

        //Supply energy to the given node
        virtual void Grow(node* nd) = 0;
        //Draw the resource
        virtual void Draw(fonts* fontViewer, bool drawAmmounts) = 0;

        //Draw the radius of this resource
        void DrawRadius();

        //Set/Get next resource in the resource linked-list
        void SetNext(resource* other);
        resource* GetNext();
        //Get the resource type
        int GetType();
        //Get the ammount of this resource
        int GetAmmount();
        //Get the position of this resource
        float GetX();
        float GetY();

        //Set the color for the resource ammount indicator
        static void SetColor();
        //Get projection, modelview and viewport matrices from OpenGL and store them in static variables
        static void GetMatrices();
    protected:
        //Light and emitter of this resource
        light* myLight;
        int myEmitter;

        //Pointer to the game object
        game* theGame;
        //Pointer to the next resource in the resource linked-list
        resource* next;

        //Type of the resource
        int myType;
        //Ammount of the resources
        int amnt;
        //Position
        float x, y;
        //Radius
        float r;

        //Some helper buffer
        char buffer[16];
        //Color for drawing ammount indicator
        static SDL_Color lightBlue;

        //Matrix buffers
        static GLdouble projectionMatrix[16];
        static GLdouble transformMatrix[16];
        static GLint viewportMatrix[4];
};

//Attack energy resource
class resourceAttack: public resource{
    public:
        resourceAttack (float posX, float posY, float radius, int ammount, game* newGame);
        void Grow(node* pl);
        void Draw(fonts* fontDrawer, bool drawAmmounts);
};

//Defence energy resource
class resourceDefence: public resource{
    public:
        resourceDefence (float posX, float posY, float radius, int ammount, game* newGame);
        void Grow(node* pl);
        void Draw(fonts* fontDrawer, bool drawAmmounts);
};

//Theta energy resource
class resourceLives: public resource{
    public:
        resourceLives (float posX, float posY, float radius, int ammount, game* newGame);
        void Grow(node* pl);
        void Draw(fonts* fontDrawer, bool drawAmmounts);
};

//Money resource
class resourceCredits: public resource{
    public:
        resourceCredits (float posX, float posY, float radius, int ammount, game* newGame);
        void Grow(node* pl);
        void Draw(fonts* fontDrawer, bool drawAmmounts);
};

//Psi energy resource
class resourceTakeover: public resource{
    public:
        resourceTakeover (float posX, float posY, float radius, int ammount, game* newGame);
        void Grow(node* pl);
        void Draw(fonts* fontDrawer, bool drawAmmounts);
};

#endif
